﻿using ETask.Api.Data;
using ETask.Api.Models;
using Org.BouncyCastle.Crypto.Utilities;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Text.Json.Serialization;

namespace ETask.Api.Dtos
{
    public class UserDto
    {
        public int Id { get; set; }

        public string Account { get; set; }

        public string Name { get; set; }

        public string Email { get; set; }

        public string Password { get; set; }

        public string Phone { get; set; }

        public int Sex { get; set; }

        public string DeptCode { get; set; }

        public string DeptName { get; set; }

        public bool IsAdmin { get; set; }

        public DateTime CreatedAt { get; set; }

        public DateTime UpdatedAt { get; set; }

        [JsonConverter(typeof(UserJsonConverter))]
        public int CreateBy { get; set; }
    }

    public class CreateUserDto
    {
        [Required(ErrorMessage = "请输入账号")]
        public string Account { get; set; }

        [Required(ErrorMessage = "用户姓名不能为空")]
        [MaxLength(4, ErrorMessage = "姓名不能超过4个字符")]
        public string Name { get; set; }

        [EmailAddress(ErrorMessage = "请输入正确的电子邮箱")]
        public string Email { get; set; }

        [Required(ErrorMessage = "密码不能为空")]
        public string Password { get; set; }

        [Phone(ErrorMessage = "请输入正确的手机号码")]
        public string Phone { get; set; }

        public int Sex { get; set; }

        public string DeptCode { get; set; }

        public bool IsAdmin { get; set; }
    }

    public class UpdateUserDto
    {
        public int Id { get; set; }

        [Required(ErrorMessage = "请输入账号")]
        public string Account { get; set; }

        [Required(ErrorMessage = "请输入姓名")]
        public string Name { get; set; }

        [EmailAddress(ErrorMessage = "请输入正确的电子邮箱")]
        public string Email { get; set; }

        [Phone(ErrorMessage = "请输入正确的手机号码")]
        public string Phone { get; set; }

        public int Sex { get; set; }

        public string DeptCode { get; set; }

        public bool IsAdmin { get; set; }

    }

    public class ResetPasswordDto
    {
        [RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$", ErrorMessage = "密码必须包含大小写字母、数字和特殊字符，且长度至少8位")]
        public string ? OldPassword { get; set; }

        [Required(ErrorMessage = "新密码不能为空")]
        [RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$", ErrorMessage = "密码必须包含大小写字母、数字和特殊字符，且长度至少8位")]
        public string NewPassword { get; set; }

        [Compare("NewPassword", ErrorMessage = "两次输入的密码不一致")]
        [Required(ErrorMessage = "请确认密码")]
        public string ConfirmPassword { get; set; }

        public int ? UserId { get; set; }
    }

    public class UserListParams
    {
        public string ? KeyWord { get; set; }

        public string ? DeptCode { get; set; }

        public PaginationParameters PageDto { get; set; }
    }
}
